// 居民健康-风险控制
import { http } from "@/utils/http";
import { globalDataStoreHook } from "@/store/modules/globalData";

// const baseUrl = VITE_REQUEST_BASE_YST;

const initCityId = globalDataStoreHook().cityId;

type overviewDataItemType = {
  metrics: string;
  trend: string;
  value: number;
};

export type overviewResType = {
  total_cost: overviewDataItemType;
  member_cnt: overviewDataItemType;
  ip_rate: overviewDataItemType;
  avg_rx_cnt: overviewDataItemType;
  avg_dx_cnt: overviewDataItemType;
  avg_cost: overviewDataItemType;
  avg_age: overviewDataItemType;
};

/**
 * 风险概况
 * */
export function getRiskOverview(cityId = initCityId) {
  return http.request<overviewResType>(
    "get",
    `http://analyse.wanhuhealth.com/first/api/one/city_overview?city_id=${cityId}`
  );
}

type memberDataType = {
  list: {
    city_id: string;
    dimension: string;
    label: string;
    value: number;
  }[];
};

export function getMemberDataByNum(cityId = initCityId) {
  return http.request<memberDataType>(
    "get",
    `http://analyse.wanhuhealth.com/first/api/one/member_dist?city_id=${cityId}&dimension=age_grp`
  );
}

export function getMemberDataByMedical(cityId = initCityId) {
  return http.request<memberDataType>(
    "get",
    `http://analyse.wanhuhealth.com/first/api/one/member_dist?city_id=${cityId}&dimension=major_disease`
  );
}

// 获取合并症数量

export function getComorbidityData(cityId = initCityId) {
  return http.request<memberDataType>(
    "get",
    `http://analyse.wanhuhealth.com/first/api/one/member_dist?city_id=${cityId}&dimension=disease_cnt`
  );
}

type presentSituationDataType = {
  series: string[];
  xaxis: string[];
};
// 现状-按会员疾病类型分布
export function getPresentSituationByMedical(
  panelType = "total_cost",
  cityId = initCityId
) {
  return http.request<presentSituationDataType>(
    "get",
    `http://analyse.wanhuhealth.com/first/api/one/member_metrics_by_dx?city_id=${cityId}&metrics=${panelType}`
  );
}

// 现状-按趋势
export function getPresentSituationByTrend(
  panelType = "total_cost",
  cityId = initCityId
) {
  return http.request<presentSituationDataType & { series2: string[] }>(
    "get",
    `http://analyse.wanhuhealth.com/first/api/one/member_metrics_trend?city_id=${cityId}&metrics=${panelType}`
  );
}

// 现状-按金额分布

export function getPresentSituationByMoney(
  panelType = "total_cost",
  cityId = initCityId
) {
  return http.request<presentSituationDataType>(
    "get",
    `http://analyse.wanhuhealth.com/first/api/one/member_metrics_dist?city_id=${cityId}&metrics=${panelType}`
  );
}

// 存储风险指标-疾病中英文键值对

type labelValueType = {
  column: string;
  column_desc: string;
  label: string;
  table_name: string;
  value: string;
};

export function getGlobalLabelValueList() {
  return http.request<labelValueType[]>(
    "get",
    `http://analyse.wanhuhealth.com/first/api/city/allCities`
  );
}

type riskDataResultType = {
  list: {
    risk_type: string;
    data: {
      city_id: string;
      member_cnt: number;
      member_cnt_complete: number;
      member_pct_complete: number;
      member_type: string;
      risk: string;
      risk_period: string;
      risk_type: string;
      risk_type_overall: string;
      value: string;
      value_num: number;
    }[];
  }[];
};
// 长期风险、短期风险 http://analyse.wanhuhealth.com/first/api/second/disease_progress_risk?city_id=340200&member_type=all

export function getRiskForecastData(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/first/api/second/disease_progress_risk?city_id=${cityId}&member_type=all`;
  return http.request<riskDataResultType>("get", url);
}

export function getMedicalPayData(cityId = initCityId, yearType) {
  const url = `http://analyse.wanhuhealth.com/first/api/three/medical_cost_risk?city_id=${cityId}&member_type=all&risk_period=${yearType}`;
  return http.request<riskDataResultType>("get", url);
}
